package com.personal.dao;

import com.personal.domain.Contact;
import com.personal.domain.obtain.KeyValue;
import com.personal.util.partDisplay.ContactPart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ContactDao {

    @Select("select * from contactinformation")
    List<Contact> selectAll();


    @Select("select id,enterpriseId,affiliatedEnterprise,nickname,name,phoneNumber,sex,position,jobNumber,telephoneNumber,documentType,status" +
            "        from contactinformation")
    List<ContactPart> selectPartAll();
    
    
    @Select("select id,enterpriseId,affiliatedEnterprise,nickname,name,phoneNumber,sex,position,jobNumber,telephoneNumber,documentType,status" +
            " from contactinformation where enterpriseId=#{enterpriseId}")
    List<ContactPart> selectPartByKey(int enterpriseId);

    @Select("select enterpriseId,affiliatedEnterprise from contactinformation")
    @Results({
            @Result(column = "enterpriseId",property = "key"),
            @Result(column = "affiliatedEnterprise",property ="value" )
    })
    List<KeyValue> selectIdAndNameAll();

    @Insert("insert into contactinformation (id,enterpriseId,affiliatedEnterprise,name, nickname, phoneNumber, dockingType, section, position, documentType," +
            "                                        documentNumber, jobNumber, sex, birthDate, telephoneNumber, wechat, QQ, email, status, remark) VALUE" +
            "                                       (null,#{enterpriseId},#{affiliatedEnterprise},#{name},#{nickname},#{phoneNumber},#{dockingType},#{section},#{position},#{documentType}," +
            "                                       #{documentNumber},#{jobNumber},#{sex},#{birthDate},#{telephoneNumber},#{wechat},#{QQ},#{email},#{status},#{remark})")
    int add(Contact contact);
    
    @Select("select * from contactinformation where id=#{id}")
    Contact getUpdateData(int id);
    @Update("update contactinformation set enterpriseId=#{enterpriseId},affiliatedEnterprise=#{affiliatedEnterprise},name=#{name},nickname=#{nickname},phoneNumber=#{phoneNumber},dockingType=#{dockingType}," +
            "                                      section=#{section},position=#{position},documentType=#{documentType},documentNumber=#{documentNumber},jobNumber=#{jobNumber}," +
            "                                      sex=#{sex},birthDate=#{birthDate},telephoneNumber=#{telephoneNumber},wechat=#{wechat},QQ=#{QQ},email=#{email},status=#{status},remark=#{remark}" +
            "                                      where id=#{id}")
    int update(Contact contact);

    @Delete("delete from contactinformation where id=#{id}")
    int delete(int id);




}
